<?php

namespace Modules\Admin\Entities;

use App\Models\Authenticatable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Modules\Admin\Database\factories\AdminFactory;

/**
 * Modules\Admin\Entities\Admin
 *
 * @property int                                                                                  $id
 * @property string                                                                               $username
 *           管理员账号
 * @property string                                                                               $name            姓名
 * @property string                                                                               $password
 * @property bool                                                                                 $enable_status   是否可用
 * @property string                                                                               $mobile
 *           绑定手机号码
 * @property string|null                                                                          $last_login_ip
 *           最后一次登录IP
 * @property string|null                                                                          $last_login_time
 *           最后一次登录时间
 * @property \Illuminate\Support\Carbon|null                                                      $deleted_at
 * @property \Illuminate\Support\Carbon|null                                                      $created_at
 * @property \Illuminate\Support\Carbon|null                                                      $updated_at
 * @property-read \Illuminate\Database\Eloquent\Collection|\Laravel\Passport\Client[]             $clients
 * @property-read int|null                                                                        $clients_count
 * @property-read \Illuminate\Database\Eloquent\Collection|\Spatie\Permission\Models\Permission[] $permissions
 * @property-read int|null                                                                        $permissions_count
 * @property-read \Illuminate\Database\Eloquent\Collection|\Spatie\Permission\Models\Role[]       $roles
 * @property-read int|null                                                                        $roles_count
 * @property-read \Illuminate\Database\Eloquent\Collection|\Laravel\Passport\Token[]              $tokens
 * @property-read int|null                                                                        $tokens_count
 * @method static \Illuminate\Database\Eloquent\Builder|BaseModel createdAtAfter($date)
 * @method static \Illuminate\Database\Eloquent\Builder|BaseModel createdAtBefore($date)
 * @method static \Illuminate\Database\Eloquent\Builder|BaseModel createdAtBetween($start, $end)
 * @method static \Illuminate\Database\Eloquent\Builder|BaseModel createdAtOfDay($data)
 * @method static \Modules\Admin\Database\factories\AdminFactory factory(...$parameters)
 * @method static \Illuminate\Database\Eloquent\Builder|BaseModel lastLoginTimeAfter($date)
 * @method static \Illuminate\Database\Eloquent\Builder|BaseModel lastLoginTimeBefore($date)
 * @method static \Illuminate\Database\Eloquent\Builder|BaseModel lastLoginTimeBetween($start, $end)
 * @method static \Illuminate\Database\Eloquent\Builder|Admin newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Admin newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Authenticatable permission($permissions)
 * @method static \Illuminate\Database\Eloquent\Builder|Admin query()
 * @method static \Illuminate\Database\Eloquent\Builder|Authenticatable role($roles, $guard = null)
 * @method static \Illuminate\Database\Eloquent\Builder|BaseModel updatedAtAfter($date)
 * @method static \Illuminate\Database\Eloquent\Builder|BaseModel updatedAtBefore($date)
 * @method static \Illuminate\Database\Eloquent\Builder|BaseModel updatedAtBetween($start, $end)
 * @method static \Illuminate\Database\Eloquent\Builder|Admin whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Admin whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Admin whereEnableStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Admin whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Admin whereLastLoginIp($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Admin whereLastLoginTime($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Admin whereMobile($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Admin whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Admin wherePassword($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Admin whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Admin whereUsername($value)
 * @mixin \Eloquent
 * @property-read \Illuminate\Database\Eloquent\Collection|\Modules\Log\Entities\Activity[] $activities
 * @property-read int|null $activities_count
 * @method static \Illuminate\Database\Eloquent\Builder|BaseModel sizeAfter($data)
 * @method static \Illuminate\Database\Eloquent\Builder|BaseModel sizeBefore($data)
 * @method static \Illuminate\Database\Eloquent\Builder|BaseModel sizeBetween($start, $end)
 */
class Admin extends Authenticatable {
    use HasFactory;

    //    protected $hidden = ['password'];

    protected static function newFactory() {
        return AdminFactory::new();
    }

    public function findForPassport($username) {
        return Admin::where('username', $username)->first();
    }

    public function guardName(): string {
        return 'admin';
    }
//    protected static function boot() {
//        parent::boot(); // TODO: Change the autogenerated stub
//        static::saving(function (Admin $admin) {
//            $admin->password = Hash::;
//        });
//    }
}
